<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

</head>
<body class="nihilo">

<div  style="width:300px;height:300px;float:right">
	<div dojoType="dijit.TitlePane" open="false" title="功能说明">
		<p>
		配置数据库全局变量。支持多数据库访问，支持mysql和sqlite。
		<br><br>规则：变量命名要求符合正则表达式 ^[A-Za-z_]{1}[A-Za-z0-9_]*。
		<br>
		</p>
			  
	</div>
	<div dojoType="dijit.TitlePane" open="false" title="如何使用">
	<p>
	举例：
	<br><br>
	
 <?
 	$p = <<<EOT
<?php
$ GLOBALS ["gDataBase"] ["db_main"] = 
array (
  'dbname' => 'main',
  'type' => 'mysql',
  'host' => 'localhost',
  'port' => '3306',
  'user' => 'root',
  'passwd' => '111111',
);
?>
EOT;
 highlight_string($p);

?>
	<br><br>
	</p>
	</div>
</div>
<div style="height:50px;">
	<div style="margin:10px;">位置: 配置管理  > 数据库设置</div>
	<div style="margin:10px;">
		<button dojoType="dijit.form.Button" onclick="dijit.byId('newDatabase').show();">新建数据库</button>
	</div>
</div>

<table style="width:600px;margin:10px">
<thead>
<tr >
<td style="border-bottom:1px solid #ccc;width:450px;background-color:#eee">数据库</td>

<td style="border-bottom:1px solid #ccc;width:150px;background-color:#eee">操作</td>
</tr>
</thead>
<tbody id="dblist">
<?php foreach($database as $item){?>
<tr id="database_<?=$item['dbname']?>">
<td><?=$item['dbname']?></td>
<td><button dojoType="dijit.form.Button" onclick="editDatabase('database_<?=$item['dbname']?>','<?=$item['dbname']?>');">修改</button><button dojoType="dijit.form.Button" onclick="deleteDatabase('database_<?=$item['dbname']?>','<?=$item['dbname']?>');">删除</button></td>
</tr>
<? }?>
</tbody>
</table>


<script>


</script>

<div dojoType="dijit.Dialog" id="newDatabase" title="新建数据库" >
	<div style="margin:5px;">
	<button dojoType="dijit.form.Button" onclick="addRow('database_table');">新增参数</button>
	</div>
	<div method="" jsid="database_form" id="database_form" dojoType="dijit.form.Form" action="">
	
	 <script type="dojo/method" event="onSubmit">
		
		if (this.validate()) {
            var xhrArgs = {
                    url:gSiteUrl+"/index.php",
        	        form: "database_form",
        	        handleAs: "json",
        	        load: function(data){
						if(data.s==200){
	            			//新增行
			            	var rowid= "database_"+data.d;
			            	var dbname = data.d;
			            	
			            	var row=document.createElement("tr");   
			            	row.id= rowid; 
		
			            	var td = document.createElement("td");
			            	var textNode=document.createTextNode(dbname); 
			            	td.appendChild(textNode);
			            	row.appendChild(td);
			            	
			            	var td = document.createElement("td");
			            	var editbtn =new dijit.form.Button({label:"修改",onClick:function(){editDatabase(rowid,dbname)}});
			            	var deletebtn =new dijit.form.Button({label:"删除",onClick:function(){deleteDatabase(rowid,dbname)}});
			            	td.appendChild(editbtn.domNode);
			            	td.appendChild(deletebtn.domNode);
			            	row.appendChild(td);		            	
			            	dojo.byId('dblist').appendChild(row);
	
			            	//表单重置
		        	      	dojo.byId('database_form').reset();
	
		        	      	  
		            	    dijit.byId('newDatabase').hide();
		        	        dojo.byId("AlertCon2").innerHTML = data.m;
		        	        dijit.byId("AlertShow2").show();
						}
						if(data.s==400){
    	        			dojo.byId("AlertCon2").innerHTML = data.m;
		        	        dijit.byId("AlertShow2").show();
    	        		}
        	        },
        	        error: function(error,ioargs){
            	      var message = httpErrorReport(ioargs.xhr.status);
        	          dojo.byId("AlertCon2").innerHTML = message;
        	          dijit.byId("AlertShow2").show();
        	        }
        	      }
         
          	var deferred = dojo.xhrPost(xhrArgs);
        	
            return false;
        } else {
           
            return false;
        }
       
    </script>
	
		<input type="hidden" name="action" value="setting">
		<input type="hidden" name="op" value="savedb">
		<table style="width:500px;margin:10px">
		<thead>
		<tr >
		<td style="border-bottom:1px solid #ccc;width:150px;background-color:#eee">变量</td>
		<td style="border-bottom:1px solid #ccc;width:250px;background-color:#eee">值</td>
		<td style="border-bottom:1px solid #ccc;width:100px;background-color:#eee">备注</td>
		</tr>
		</thead>
		<tbody id="database_table">
		<tr id="row_dbname">
		<td><input dojoType="dijit.form.TextBox" style="width:150px" type="text" name="name_dbname" value="dbname" readonly></td>
		<td><input dojoType="dijit.form.ValidationTextBox" required="true" type="text" name="valu_dbname" id="valu_dbname" value="" regExp="^[A-Za-z_]{1}[A-Za-z0-9_]*" invalidMessage="变量名不符合规则:^[A-Za-z_]{1}[A-Za-z0-9_]*"></td>
		<td><label>数据库名</label></td>
		</tr>
		<tr id="row_type">
		<td><input dojoType="dijit.form.TextBox" style="width:150px" type="text" name="name_type" value="type" readonly></td>
		<td><input dojoType="dijit.form.ValidationTextBox" required="true" type="text" name="valu_type" id="valu_type" value="" regExp="^[A-Za-z_]{1}[A-Za-z0-9_]*" invalidMessage="变量名不符合规则:^[A-Za-z_]{1}[A-Za-z0-9_]*"></td>
		<td><label>类型</label></td>
		</tr>
		<tr id="row_host">
		<td><input dojoType="dijit.form.TextBox" style="width:150px" type="text" name="name_host" value="host" readonly></td>
		<td><input dojoType="dijit.form.ValidationTextBox" required="true" type="text" name="valu_host" id="valu_host" value=""></td>
		<td><label>主机地址</label></td>
		</tr>
		<tr id="row_port">
		<td><input dojoType="dijit.form.TextBox" style="width:150px" type="text" name="name_port" value="port" readonly></td>
		<td><input dojoType="dijit.form.ValidationTextBox" required="true" type="text" name="valu_port" id="valu_port" value="" regExp="[0-9]+" invalidMessage="变量名不符合规则:[0-9]+"></td>
		<td><label>端口</label></td>
		</tr>
		<tr id="row_user">
		<td><input dojoType="dijit.form.TextBox" style="width:150px" type="text" name="name_user" value="user" readonly></td>
		<td><input dojoType="dijit.form.ValidationTextBox" required="true" type="text" name="valu_user" id="valu_user" value="" ></td>
		<td><label>用户名</label></td>
		</tr>
		<tr id="row_passwd">
		<td><input dojoType="dijit.form.TextBox" style="width:150px" type="text" name="name_passwd" value="passwd" readonly></td>
		<td><input dojoType="dijit.form.ValidationTextBox" required="true" type="text" name="valu_passwd" id="valu_passwd" value=""></td>
		<td><label>密码</label></td>
		</tr>
		</tbody>
		<tfoot>
		<tr>
		     <td colspan="2" align="center">
		       <button dojoType="dijit.form.Button" type="submit">保存</button>
		       <button dojoType="dijit.form.Button" type="reset">重置</button>
		       </td>
		   </tr>
		 </tfoot>	
		</table>
	</div>
</div>



<div dojoType="dijit.Dialog" id="editDatabase" title="修改数据库" >
	<div style="margin:5px;">
			<button dojoType="dijit.form.Button" onclick="addRow('database_edit_table');">新增参数</button>
	</div>
	<div method="" jsid="database_edit_form" id="database_edit_form" dojoType="dijit.form.Form" action="">
	<script type="dojo/method" event="onSubmit">
		 if (this.validate()) {
            var xhrArgs = {
            		url:gSiteUrl+"/index.php",
        	        form: 'database_edit_form',
        	        handleAs: "json",
        	        load: function(data){
    	        		if(data.s==200){
	    	        		//alert(data);
							//删除旧行
							var old_database = dojo.byId("edit_dbname").value;
							//alert(old_database);
	            			dojo.byId("dblist").removeChild(dojo.byId("database_"+old_database));
	    	        		
			            	//新增行
			            	var rowid= "database_"+data.d;
			            	
			            	var dbname = data.d;
			            	
			            	var row=document.createElement("tr");   
			            	row.id= rowid; 
			
			            	var td = document.createElement("td");
			            	var textNode=document.createTextNode(dbname); 
			            	td.appendChild(textNode);
			            	row.appendChild(td);
			            	
			            	var td = document.createElement("td");
			            	var editbtn =new dijit.form.Button({label:"修改",onClick:function(){editDatabase(rowid,dbname)}});
			            	var deletebtn =new dijit.form.Button({label:"删除",onClick:function(){deleteDatabase(rowid,dbname)}});
			            	td.appendChild(editbtn.domNode);
			            	td.appendChild(deletebtn.domNode);
			            	row.appendChild(td);		            	
			            	dojo.byId('dblist').appendChild(row);
			            	
			            	//表单重置
		        	      	//dojo.byId('database_edit_form').reset();
	 	      	  
		            	    dijit.byId('editDatabase').hide();
		        	        dojo.byId("AlertCon2").innerHTML = data.m;
		        	        dijit.byId("AlertShow2").show();
    	        		}
    	        		if(data.s==400){
    	        			dojo.byId("AlertCon2").innerHTML = data.m;
		        	        dijit.byId("AlertShow2").show();
    	        		}
        	        },
        	        error: function(error,ioargs){
            	      var message = httpErrorReport(ioargs.xhr.status);
        	          dojo.byId("AlertCon2").innerHTML = message;
        	          dijit.byId("AlertShow2").show();
        	        }
        	      }
         
          	var deferred = dojo.xhrPost(xhrArgs);
        	
            return false;
        } else {
           
            return false;
        }
		</script>
		<input type="hidden" name="action" value="setting">
		<input type="hidden" name="op" value="updatedb">
		<input type="hidden" name="edit_dbname" id="edit_dbname" value="">
		
		<table style="width:500px;margin:10px">
		<thead>
		<tr >
		<td style="border-bottom:1px solid #ccc;width:150px;background-color:#eee">变量</td>
		<td style="border-bottom:1px solid #ccc;width:250px;background-color:#eee">值</td>
		<td style="border-bottom:1px solid #ccc;width:100px;background-color:#eee">操作</td>
		</tr>
		</thead>
		<tbody id="database_edit_table">
		
		</tbody>
		<tfoot>
		<tr>
		     <td colspan="2" align="center">
		       <button dojoType="dijit.form.Button" type="submit">保存</button>
		       <button dojoType="dijit.form.Button" type="reset">重置</button>
		       </td>
		   </tr>
		 </tfoot>	
		</table>
	</div>
</div>



</body>
</html>